package test

import (
	"errors"
	"github.com/lestrrat-go/jwx/v2/jwk"
)

var privateKey = `{
  "alg": "RS256",
  "d": "hsVXyJ1VjNFjiRqLE6bNZrAJDlnE33ptT4XpbPylfhlLfLB_OOB_YC5e4cBBoXlWaIJzYQ-qX0eSD2OdNg1JC0TgyQvwOqc9y6EKGyGu2asyHsJxLy8IiaqoqdqgiV0N_DsCYzt5Ew2nJq1P3XYqO5TJBpISixO47BEHaBgQeQBwSfmV3hmGYYTzJz6bwDNDhrBtg-2WiTfaq-3trorxo5Ww17-icr69Yad47Y4EIjKNL8SLPnWCt4NZTuT6Qs6QeUn-wOYPMaLh11DyZBNOuqiNWKjs_xPoi6C8jS1Jua0loTJXblDuMTDRL6-k82SByi7q8Yywr2TAdrotYbXF8kmaMmzW2gdQhkJs3xeNm3RyoIZOiU-7uzykSG8EkC0bx3mhIGVW_IOpzD2Xo2abbweR-PyX5z07qn9F1BHScdXViDmMNq2FU25D9K4FrRUqg8k5jpzkFrhcyPuw_hwB_BheNZgxulBbKy686qC6vTT41kZceD34PdBlMpzPctsK60GQWow8qs_OTQjD5ff_sTrNk4wzFpzo74ctcHOCZavW3gnZjhrMO9yHKGUBvgQJCiQ3C9nAkEP4pSOtk3nYgNLaWFftUYS_JKf36PcpM-YJYZEO33ayrcK19fp0aZbP11W1RpCs3jOaVWGwsS3xFE-4w_0xTbWoJACBgRENy_k",
  "dp": "qtwBo39K7eDKXoyXn1YUwk8hzaNwhDqfhWPMGHiPjS9W5PLdEpfaxkoMK38oiYkb0ohmEe_z54fmMTAD037lYAbQpW-Al8z1J0qfFEmSgmCVHL80u8Tvq6OtCJojJUDDMEBL-s67FGepXekjNCyS7S1zXJ_CFx619VQv5hadLga2p5TL8pYBjNBfS9FKFeZmaIF6tkz_fNEwud9kOXW1gOcpbgTmBZgDxlHbCiQcL44q7vdKjwHY1a6bi9cf9uvuJ7E_3ysWycTKaH3q0lveTe8I1ovZy2QbuvzEKuF9P_9B8rZiWYbPx6H9bPzd1Tis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"
}`

type JwkManager struct{}

func (m JwkManager) GenerateKey() (jwk.Key, error) {
	return nil, errors.New("not implemented")
}

func (m JwkManager) GetPublicKeys() (jwk.Set, error) {
	key, err := getJwk()
	if err != nil {
		return nil, err
	}
	publicKey, err := jwk.PublicKeyOf(key)
	if err != nil {
		return nil, err
	}
	set := jwk.NewSet()
	err = set.AddKey(publicKey)
	if err != nil {
		return nil, err
	}
	return set, nil
}

func (m JwkManager) GetSigningKey() (jwk.Key, error) {
	return getJwk()
}

func getJwk() (jwk.Key, error) {
	return jwk.ParseKey([]byte(privateKey))
}
